import axios from "axios"
import {ElMessage} from "element-plus";
import {Key} from "../System/SystemContant";

let server = axios.create({
    baseURL: '/api',
    timeout: 5000
})

const token = localStorage.getItem(Key)

server.interceptors.request.use((config) => {
    if (token) {
        config.headers['authorization'] = token
    }
    return config
}, error => {
    ElMessage.error(error)
    return Promise.reject(error)
})

server.interceptors.response.use((result) => {
    return result.data
})

export default server